<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/renting/css/public.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/renting/css/index.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/header.css" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <title>首页</title>
    <script src="${pageContext.request.contextPath}/renting/js/jQuery-3.4.1.js"></script>
    <style>
        #sel{
            float: left;
            width: 122px;
            height: 40px;
            margin-left: 54px;
            margin-top: 8px;
            border-radius: 30px;
            text-align: center;
            padding: 0 30px;
            outline: 0;
            font-size: 16px;
            appearance: none;
            -moz-appearance: none;
            -webkit-appearance: none;
        }
    </style>


</head>
<body>
<div class="header">
    <div class="nav">
        <a href="${pageContext.request.contextPath}/renting/index.jsp" class="nav_title">好客租房</a>
        <%--        <select name="city" lay-search="" id="sel" lay-filter="sel_s2">--%>

        <%--        </select>--%>
        <input type="button" value="${city.name}" id="sel">
        <input type="hidden" value="${city.rid}" id="selId">

        <script>
            //城市选择框
            $.ajax({
                url:"${pageContext.request.contextPath}/city/queryAllCity",
                type:"post",
                data:{"rid":${city.rid},"showWi":1},
                dataType:"json",
                success:(rs)=>{
                    $.each(rs,function (i,j){
                        if(j.rid==${city.rid}){
                            $("#sel").append("<option value='"+j.rid+"' selected>"+j.name+"</option>");
                        }else {
                            $("#sel").append("<option value='"+j.rid+"'>"+j.name+"</option>");
                        }
                    })
                }
            })
        </script>

        <ul class="nav_ul" >
            <li><a href="" style="color: #2983C9;">首页</a></li>
            <li><a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp">轻松找房</a></li>
            <c:if test="${drom!=null}">
                <li><a href="${pageContext.request.contextPath}/renting/pages/onther/entry.jsp">房东入驻</a></li>
            </c:if>
            <li><a href="${pageContext.request.contextPath}/renting/pages/onther/chat_news.jsp">消息</a></li>

            <li><a href="${pageContext.request.contextPath}/renting/pages/onther/login.jsp">登录</a></li>
        </ul>
        <img src="${pageContext.request.contextPath}/renting/img/icon/lianxi-1.png" class="nav_img" style="margin-top: -20px;">
        <p class="nav_phone">
            <span>13301131116</span>
            <span>13301131116</span>
        </p>
    </div>
</div>


<!-- banner -->
<div class="banner-box">
    <div class="banner-content">
        <p class="banner-title">
            全网新房源，不挑剩下的
        </p>
        <div class="banner-search">
            <input type="text" placeholder="" id="search" value="三室一厅">
            <a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp">
                <img src="${pageContext.request.contextPath}/renting/img/icon/sousuo.png">
            </a>
            <!-- 下拉提示框 -->
            <div class="search-down">
                <div class="search-hint"> 提示2 </div>
                <div class="search-hint"> 提示1 </div>
                <div class="search-hint"> 提示3 </div>
                <div class="search-hint"> 提示4 </div>
                <div class="search-hint"> 提示5 </div>
            </div>
        </div>
    </div>
</div>

<div class="content">
    <div class="content-nav">
        <div class="content-subnav">
            <a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp" class="subnav-ico">
                <img src="${pageContext.request.contextPath}/renting/img/icon/fangzi.png">
            </a>
            <a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp" class="subnav-caption">整租</a>
        </div>
        <div class="content-subnav">
            <a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp" class="subnav-ico">
                <img src="${pageContext.request.contextPath}/renting/img/icon/yunxuhezu.png">
            </a>
            <a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp" class="subnav-caption">合租</a>
        </div>
        <div class="content-subnav">
            <a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp" class="subnav-ico">
                <img src="${pageContext.request.contextPath}/renting/img/icon/ditu.png">
            </a>
            <a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp" class="subnav-caption">地图找房</a>
        </div>
        <div class="content-subnav">
            <a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp" class="subnav-ico">
                <img src="${pageContext.request.contextPath}/renting/img/icon/fangzi.png">
            </a>
            <a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp" class="subnav-caption">去出租</a>
        </div>
    </div>
    <!-- 推荐房源 -->
    <div class="recommend">
        <div class="recommend-tilte">
            <div class="recommend-caption">推荐房源</div>
            <div class="recommend-more">
                <a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp">更多></a>
            </div>
        </div>
        <div class="recommend-list" id="Lis">
        </div>
        <script>
            //查询主页信息1q1
            $(function (){
                var txt={"cityId":${city.rid}}
                $.ajax({
                    url:"${pageContext.request.contextPath}/house/queryHouseLimit?limit=3&page=1&showWi=2",
                    type:"post",
                    data:"condition="+JSON.stringify(txt),
                    dataType:"JSON",
                    success:(rs)=>{
                        console.log(rs);
                        $.each(rs,function (i,j){
                            var txt;
                            switch (j.paymentMethod) {
                                case 0:
                                    txt='免押';
                                    break;
                                case 1:
                                    txt='压一付一';
                                    break;
                                case 2:
                                    txt='压一付二';
                                    break;
                                case 3:
                                    txt='压一付三';
                                    break;
                            }
                            var Listings=$("<a href='${pageContext.request.contextPath}/house/queryHouseById?rid="+j.rid+"&showWi=2'><div><img src='img/"+j.housePicture+"'style='height: 200px;width: 300px'></div><div class='tj-name'> <span>"+j.communityName+"</span> </div> <div class='tj-details'><span>"+j.houseType+"</span>/"+j.constructionArea+"平方米/"+j.towards+" </div> <div class='tj-tag'> <span>"+txt+"</span> <span>"+j.rentalType+"</span> <span>"+j.renovationCondition+"</span> </div> <div class='tj-money'> <span>"+j.price+"</span>元/月 </div> </a>")
                            Listings.appendTo("#Lis");
                        })
                    }
                });
            });

        </script>
    </div>

    <!-- 热门区域 -->
    <div class="recommend">
        <div class="recommend-tilte">
            <div class="recommend-caption">热门区域</div>
            <div class="recommend-more">
                <a href="pages/onther/Findroom.html">更多></a>
            </div>
        </div>
        <div class="recommend-list" id="Ting">
        </div>
    </div>
    <!-- 热门区域 -->
    <script>
        //查询主页信息
        $(function (){
            // 19586
            var txt={"cityId":${city.rid},"browseNumber":"browseNumber"}
            $.ajax({
                url:"${pageContext.request.contextPath}/house/queryHouseLimit?limit=3&page=1&showWi=2",
                type:"post",
                data:"condition="+JSON.stringify(txt),
                dataType:"JSON",
                success:(rs)=>{
                    console.log(rs);
                    $.each(rs,function (i,j){
                        console.log(rs);
                        var txt;
                        switch (j.paymentMethod) {
                            case 0:
                                txt='免押';
                                break;
                            case 1:
                                txt='压一付一';
                                break;
                            case 2:
                                txt='压一付二';
                                break;
                            case 3:
                                txt='压一付三';
                                break;
                        }
                        var Listings=$("<a href='${pageContext.request.contextPath}/house/queryHouseById?rid="+j.rid+"&showWi=2'> <div><img src='img/"+j.housePicture+"'style='height: 200px;width: 300px'></div><div class='tj-name'> <span>"+j.communityName+"</span> </div> <div class='tj-details'><span>"+j.houseType+"</span>/"+j.constructionArea+"平方米/"+j.towards+" </div> <div class='tj-tag'> <span>"+txt+"</span> <span>"+j.rentalType+"</span> <span>"+j.renovationCondition+"</span> </div> <div class='tj-money'> <span>"+j.price+"</span>元/月 </div> </a>")
                        Listings.appendTo("#Ting");
                    })
                }
            });
        });

    </script>

</div>

<div class="center-box">
    <div class="center">
        <a href="#" class="center-ico">
            <div class="center-dbx">
                <img src="${pageContext.request.contextPath}/renting/img/icon/aq-white.png" >
            </div>
            <p>安全</p>
            <span>真实安全防盗天下无贼</span>
        </a>
        <a href="#" class="center-ico">
            <div class="center-dbx">
                <img src="${pageContext.request.contextPath}/renting/img/icon/cn-white.png" >
            </div>
            <p>承诺</p>
            <span>我们只用实力说话</span>
        </a>
        <a href="#" class="center-ico">
            <div class="center-dbx">
                <img src="${pageContext.request.contextPath}/renting/img/icon/pz-white.png" >
            </div>
            <p>品质</p>
            <span>简约时尚宜家风格</span>
        </a>
        <a href="#" class="center-ico">
            <div class="center-dbx">
                <img src="${pageContext.request.contextPath}/renting/img/icon/fw-white.png" >
            </div>
            <p>服务</p>
            <span>真诚实意对待每一个客户</span>
        </a>
    </div>
</div>

<!-- 租房资讯 -->
<div class="information">
    <div class="information-title">
        <h2>租房资讯</h2>
    </div>
    <div class="information-list">

    </div>
    <a href="#" class="btn-more">
        查看更多
    </a>
</div>
<!-- 租房资讯 -->
<script>
    //查询主页信息
    <%--$(function (){--%>
    <%--    var txt={"provinceName":"天津市"}--%>
    <%--    $.ajax({--%>
    <%--        url:"${pageContext.request.contextPath}/information/queryInformationLimit",--%>
    <%--        type:"post",--%>
    <%--        success:(rs)=>{--%>
    <%--            console.log("咨询！！")--%>
    <%--        }--%>
    <%--    });--%>
    <%--});--%>
</script>
<!-- 底部 -->
<div class="footer">
    泸公网安备 <span>31011402005354</span>号
</div>
</body>
</html>
<script src="${pageContext.request.contextPath}/renting/js/header.js"></script>
<script src="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/renting/js/index.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    $(function (){

        var socket=new WebSocket("ws://${pageContext.request.getServerName()}:${pageContext.request.getServerPort()}${pageContext.request.contextPath}/ws/websocket/1/2");

        //接收服务器返回的聊天信息
        socket.onmessage=(res)=>{
            var obj=JSON.parse(res.data);
            var city=obj.city.toString();
            $.ajax({
                url:"${pageContext.request.contextPath}/city/queryCityByName",
                type:"post",
                data:"cityName="+city,
                success:function (rs){
                    var bbc=JSON.parse(rs);
                    // alert(bbc.rid)
                    $("#sel").val(bbc.name);
                    $("#selId").val(bbc.rid);
                    upCity(bbc.rid);
                }
            })
            return false;
        }
    });

    $.ajax({
        url:'${pageContext.request.contextPath}/information/queryInformationLimit',
        type:'post',
        async:false,
        data:{"limit":2,"page":1,"showWi":2},
        dataType:"json",
        success:function (redata){
            console.log(redata);
            for(var ia=0;ia<redata.length;ia++){
                $(".information-list").append("<div class='information-content'>"+
                    "<a href='${pageContext.request.contextPath}/information/queryInformationById?rid="+redata[ia].rid+"&showWi=2' class='content-left'></a>"+
                    "<div class='content-right'>"+
                    "<div class='content-right-title'>"+
                    "<a href='${pageContext.request.contextPath}/information/queryInformationById?rid="+redata[ia].rid+"&showWi=2'>"+redata[ia].title+"</a>"+
                    "</div>"+
                    "<span class='content-time'>"+dateToStr(redata[ia].createTime)+"</span>"+
                    "<div class='content-right-text'>"+
                    "<p>"+redata[ia].preface+"</p>"+
                    "<a href='${pageContext.request.contextPath}/information/queryInformationById?rid="+redata[ia].rid+"&showWi=2'>查看详情</a>"+
                    "</div>"+
                    "</div>"+
                    "</div>")
            }



        },
        erro:function (e){
            console.log(e);
        }
    })


    function dateToStr(timestamp) {
        if(timestamp!=null){
            var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
            Y = date.getFullYear() + '-';
            M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
            D = date.getDate() + ' ';
            return Y+M+D;
        }else{
            return "";
        }
    }

    layui.use(['table', 'form','layer'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        $("#sel").click(function () {
            var index = layer.open({
                title: "<a href='${pageContext.request.contextPath}/renting/index.jsp' class='nav_title'><b><span style='font-size:30px;margin-left:150px;'>好客租房</span></b></a>",
                type: 2,
                shade: 0.2,
                shadeClose: true,
                scrollbar: false,
                area: ['100%', '100%'],
                content: '${pageContext.request.contextPath}/city/queryAllCity',
                end:function (rs){
                }
            });
        })

        //选择城市
        upCity=function (id) {
            var txt={"cityId":id}
            var txt1={"cityId":id,"browseNumber":"browseNumber"}
            //清空数据
            $("#Lis").html(null);
            $("#Ting").html(null);
            $.ajax({
                url:"${pageContext.request.contextPath}/house/queryHouseLimit?limit=3&page=1&showWi=2",
                type:"post",
                data:"condition="+JSON.stringify(txt),
                dataType:"JSON",
                success:(rs)=>{
                    console.log(rs);
                    $.each(rs,function (i,j){
                        var txt;
                        switch (j.paymentMethod) {
                            case 0:
                                txt='免押';
                                break;
                            case 1:
                                txt='压一付一';
                                break;
                            case 2:
                                txt='压一付二';
                                break;
                            case 3:
                                txt='压一付三';
                                break;
                        }
                        var Listings=$("<a href='${pageContext.request.contextPath}/house/queryHouseById?rid="+j.rid+"&showWi=2'> <div><img src='img/"+j.housePicture+"'style='height: 200px;width: 300px'></div><div class='tj-name'> <span>"+j.communityName+"</span> </div> <div class='tj-details'><span>"+j.houseType+"</span>/"+j.constructionArea+"平方米/"+j.towards+" </div> <div class='tj-tag'> <span>"+txt+"</span> <span>"+j.rentalType+"</span> <span>"+j.renovationCondition+"</span> </div> <div class='tj-money'> <span>"+j.price+"</span>元/月 </div> </a>")
                        Listings.appendTo("#Lis");
                    })
                }
            });
            $.ajax({
                url:"${pageContext.request.contextPath}/house/queryHouseLimit?limit=3&page=1&showWi=2",
                type:"post",
                data:"condition="+JSON.stringify(txt1),
                dataType:"JSON",
                success:(rs)=>{
                    $.each(rs,function (i,j){
                        console.log(rs);
                        var txt;
                        switch (j.paymentMethod) {
                            case 0:
                                txt='免押';
                                break;
                            case 1:
                                txt='压一付一';
                                break;
                            case 2:
                                txt='压一付二';
                                break;
                            case 3:
                                txt='压一付三';
                                break;
                        }
                        var Listings=$("<a href='${pageContext.request.contextPath}/house/queryHouseById?rid="+j.rid+"&showWi=2'> <div><img src='img/"+j.housePicture+"'style='height: 200px;width: 300px'></div><div class='tj-name'> <span>"+j.communityName+"</span> </div> <div class='tj-details'><span>"+j.houseType+"</span>/"+j.constructionArea+"平方米/"+j.towards+" </div> <div class='tj-tag'> <span>"+txt+"</span> <span>"+j.rentalType+"</span> <span>"+j.renovationCondition+"</span> </div> <div class='tj-money'> <span>"+j.price+"</span>元/月 </div> </a>")
                        Listings.appendTo("#Ting");
                    })
                }
            });
        }

    });

    var login=sessionStorage.getItem("login");
    var url="";
    if(login==1){
        url="${pageContext.request.contextPath}/renting/pages/tenant/inspection.jsp";
    }
    if(login==2){
        url="${pageContext.request.contextPath}/renting/pages/landlord/release.jsp";
    }
    judge_login(url,"${pageContext.request.contextPath}/renting/pages/onther/login.jsp");

</script>